<?php
namespace app\common\model\tyyh;

class UserWalletBalanceOrder extends CUBase {
    protected $hidden = ['transaction_id', 'sub_mch_id', 'delete'];

	protected static function init()
    {
        parent::init();
        
        // 注册 before_insert 事件
        self::beforeInsert(function ($data) {
        	$status = loadEnum('OrderStatus');
        	$data['transaction_id'] = '';
            $data['route'] = '';
            $data['pay_type'] = loadEnum('PayType')->code2key('notify');
            $data['paytime'] = 0;
            $data['status'] = $status->code2key('daizhifu');
            $data['delete'] = 0;
            return $data;
        });
    }

    //获取订单正在申请退款的退款单数量
    protected function getRefundAttr($value, $data) {
        $model = loader()->loadModel('tyyh\\UserWalletBalanceRefund');
        $model->where('oid', $data['id']);
        $model->where('status', 'neq', loadEnum('UserWalletBalanceRefundStatus')->code2key('daishenhe'));
        return $model->find();
    }
}
